package com.example.mvctest

import android.R.id.button2
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat



private fun Int.setOnClickListener(function: () -> Unit) {}

class MainActivity : AppCompatActivity() {

    private var count = 1

    @SuppressLint("SetTextI18n")

    val expert = ProgramExpert()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        val spinner = findViewById<Spinner>(R.id.spinner)
        val button2 = findViewById<Button>(R.id.button2)
        val textView = findViewById<TextView>(R.id.textView)



        button2.setOnClickListener {
            textView.text = expert.getLanguage(spinner.selectedItem.toString())
        }

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val button = findViewById<Button>(R.id.button)
        val linearLayout = findViewById<LinearLayout>(R.id.linearLayout)
        val scrollView = findViewById<ScrollView>(R.id.ScrollView)

        button.setOnClickListener {
            val textView = TextView(this)
            textView.text = "这是一个新的TextView: $count"
            textView.textSize = 18f
            textView.setPadding(0, 16, 0, 16)
            linearLayout.addView(textView)


            scrollView.post {
                scrollView.smoothScrollTo(0, linearLayout.bottom)
            }

            count++
        }

    }
}